import {systemStoreHook} from "@/stores/modules";
import { commonState } from '@/common/index.js'

const systemStore = systemStoreHook();
export const pageSearch = reactive({
    pageNumber: commonState.pageNumber,
    pageSize: commonState.pageSize
});
export const tableState = reactive({
    totalCount: 0,
    records: []
});

export const state = reactive({
    selectedRowKeys: [],
    loading: false,
    subLoading: false,
});
export const setLoading = (loading) => {
    state.loading = loading;
}

export const setSubLoading = (loading) => {
    state.subLoading = loading;
}

//表单列表
export const columns = [
    {
        title: '用户名',
        dataIndex: 'userName',
        key: 'userName',
        align: 'center',
        width: 160,
    },
    {
        title: '账号',
        dataIndex: 'account',
        key: 'account',
        align: 'center',
        width: 160,
    },
    {
        title: '昵称',
        dataIndex: 'nickname',
        key: 'nickname',
        align: 'center',
    },
    {
        title: '联系方式',
        dataIndex: 'mobile',
        key: 'mobile',
        align: 'left'
    },
    {
        title: '状态',
        dataIndex: 'status',
        key: 'status',
        align: 'center',
        width: 100
    },
    {
        title: '时间',
        dataIndex: 'dateTime',
        key: 'dateTime',
        align: 'center',
        width: 260
    },
    {
        title: '操作',
        key: 'operation',
        fixed: 'right',
        align: 'center',
        width: 160,
    }
]
let validatePassForm = (rule, value) => {
    if (value === "") {
        return Promise.reject("请输入密码");
    }
    if (value.length < 6 || value.length > 16) {
        return Promise.reject("密码长度必须在6到16个字符之间");
    }
    if (!/[0-9]/.test(value) || !/[a-zA-Z]/.test(value)) {
        return Promise.reject("密码必须包含数字和字母");
    }
    return Promise.resolve();
}
export const rules = reactive({
    userName: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
    account: [{ required: true, message: '请输入账号', trigger: 'blur' }],
    gender: [{ required: true, message: '请选择性别', trigger: 'blur' }],
    password: [{ required: true, validator: validatePassForm, trigger: 'blur' }],
    mobile: [{ required: true, message: '请输入手机号', trigger: 'blur' }],
    roleIds: [{ required: true, message: '请选择角色', trigger: 'blur' }],
    email: [{ required: true, message: '请输入邮箱', trigger: 'blur' }],
    enabled: [{ required: true, message: '请选择状态', trigger: 'blur' }],
    locked: [{ required: true, message: '请选择状态', trigger: 'blur' }],
});
//查询
export const searchState = reactive ({
})
//明细
export const detailState = reactive ({
    enabled: true,
    locked: false,
    adminExtend: {
        departmentId: null
    }
})
//修改密码
export const rePasswordState = reactive({
    id: '',
    password: '',
    confirmPassword: ''
});
//设置查询参数
export function setSearchParam () {
    Object.assign(pageSearch, systemStore.getUserSearch);
    return pageSearch;
}
